<!DOCTYPE html>

<html>
<head>
<title>HTML5 配送员测试2</title>
</head>
<body>
	<div>
		<input type="button" value="Start" onclick="start()" />
        <input id="content" type="text">
        <input type="button" value="发送" onclick="send()">
	</div>
	<div id="messages"></div>
	<script type="text/javascript">
		var webSocket = new WebSocket('ws://8.129.238.209:6680');
		webSocket.onerror = function(event) {
			alert(event.data);
		};
		//与WebSocket建立连接
		webSocket.onopen = function(event) {
			document.getElementById('messages').innerHTML = '12342';
		};
		//处理服务器返回的信息
		webSocket.onmessage = function(event) {
			console.log(event.data)
		};
		function start() {
			//向服务器发送请求
			webSocket.send(JSON.stringify({
				"type":2,
				"token":"{{$data['token']}}",
				"Authorization":"{{$data['token']}}",
				"role":"{{$data['role']}}"
			}));
		}

		function send() {
		    content = document.getElementById('content').value;
		    console.log(content);
		    var data = JSON.stringify({
		    	"type":22,
				"token":"{{$data['token']}}",
				"Authorization":"{{$data['token']}}",
				"order_id":88,
				"to_role":"staff",
				"staff_id":1,
		    });
		    webSocket.send(data);
		}
</script>
</body>
</html>

